package solution._0070._0078;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chen_snow
 * Date: 2021/6/22 21:16
 * Description: 子集
 */
public class Solution {
    public List<List<Integer>> subsets(int[] nums) {
        ArrayList<List<Integer>> result = new ArrayList<List<Integer>>();
        result.add(new ArrayList<>());
        backTrace(result, nums, 0);
        return result;
    }

    public void backTrace(ArrayList<List<Integer>> result, int[] nums, int index) {
        if (index == nums.length) {
            return;
        }

        ArrayList<List<Integer>> tmp = new ArrayList<>(result);

        for (int i = 0; i < tmp.size(); i++) {
            ArrayList<Integer> list = new ArrayList<>(result.get(i));
            list.add(nums[index]);
            result.add(list);
        }

        backTrace(result, nums, index + 1);
    }
}
